#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int num;
    int x;
}f[1005];
bool cmp(node a,node b)
{
    return a.x>b.x;
}
int main (){
    long long count,tempSum=0,sum=0,maxx=0;
    cin>>count;
    for (int i = 0; i < count; ++i) {
        cin>>f[i].x;
    }
    for (int i = 0; i < count; ++i) {
        cin>>f[i].num;
    }
    sort(f,f+count,cmp);
    for (int k = 0; k < count; ++k) {
        for (int i = 0; i < f[k].num; ++i) {
            tempSum+=f[k].x;
            sum += tempSum;

            maxx=max(maxx,sum);
        }
    }
    cout<<maxx<<endl;
    return 0;
}